package com.cardone.platform.common.action;

import com.cardone.common.annotation.RunAction;
import com.cardone.common.annotation.support.ErrorRunActionSupport;
import com.cardone.context.ContextHolder;
import com.cardone.platform.common.dto.OperateLogDto;
import com.cardone.platform.common.service.OperateLogService;
import org.apache.commons.collections.MapUtils;

import java.util.Map;
import java.util.UUID;

/**
 * Created by c100000001 on 15-2-11.
 */
public class ErrorOperateLogAction extends ErrorRunActionSupport {
    @Override
    protected void run(RunAction runAction, Map<String, Object> parameterMap) {
        final OperateLogDto insertOperateLog = new OperateLogDto();

        insertOperateLog.setId(UUID.randomUUID().toString());
        insertOperateLog.setTypeTypeCode(runAction.errorTypeCode());
        insertOperateLog.setTypeCode(runAction.errorCode());
        insertOperateLog.setCode(runAction.errorCode());
        insertOperateLog.setUserId(MapUtils.getString(parameterMap, "userId"));
        insertOperateLog.setMessage(MapUtils.getString(parameterMap, "message"));

        ContextHolder.getBean(OperateLogService.class).insertByCode(insertOperateLog);
    }
}
